#ifndef FRAGMENTATION_DEMO_H
#define FRAGMENTATION_DEMO_H



#include "Ground.h"
#include "TestSphere.h"
#include "Light.h"
#include "Singleton.h"
#include "EventHandler.h"

#include <vector>

#include "LinearMath/btAlignedObjectArray.h"
//#include "LinearMath/btConvexHullComputer.h"

class btDynamicsWorld;
class btBroadphaseInterface;
class btCollisionShape;
class btOverlappingPairCache;
class btCollisionDispatcher;
class btConstraintSolver;
class btDefaultCollisionConfiguration;
class TestCuboid;
//class PreFracturedCuboid;



class FragmentationDemo : public Uncopyable, public EventHandler
{
public:
	
	typedef std::vector<std::pair<bool, btRigidBody*>> AddRemoveBodies;


	void ResetScene();
	bool InitPhysics();
	void ExitPhysics();
	void Update();
	void Draw();

	void AddOrRemoveRigidBody(bool addOrRemove, btRigidBody* body); 

	void AddCollisionShape(btCollisionShape* shape);
	btDynamicsWorld* GetDynamicsWorld();
	void BTCheckPairs();
	void SafelyAddRemoveRigidBodies();

	void OnKeyboardEvent(const SDL_KeyboardEvent& k);

private:
	FragmentationDemo();
	friend class Singleton<FragmentationDemo>;
	
	Light m_light;
	//GroundPlane m_ground;
	
//	PreFracturedCuboid* m_pPreFrac;
	TestCuboid* m_pFractureCuboid;
	Ground* m_pGround;

	
	AddRemoveBodies m_addRemoveBodies;

	//Bullet Physics variables
	btDynamicsWorld* m_pDynamicsWorld;
	btAlignedObjectArray<btCollisionShape*>	m_collisionShapes;
	btBroadphaseInterface*	m_pBroadphase;
	btCollisionDispatcher*	m_pDispatcher;
	btConstraintSolver*	m_pSolver;
	btDefaultCollisionConfiguration* m_pCollisionConfiguration;

};

typedef Singleton<FragmentationDemo> TheFragmentationDemo;

#endif